/**
 * 
 */
package edu.byu.nlp.pipes;

import java.util.List;

import com.google.common.base.Function;
import com.google.common.collect.Lists;

/**
 * Builds a pipe that process an arbitrary number of pipes serially.
 * This class assists with the generics.
 * 
 * @author robbie
 *
 */
public class SerialPipeBuilder<IL, ID, OL, OD> {

	private List<Pipe> pipes = Lists.newArrayList();
	
	public <L, D> SerialPipeBuilder<IL, ID, L, D> add(Pipe<OL, OD, L, D> p) {
		pipes.add(p);
		return (SerialPipeBuilder<IL, ID, L, D>) this;
	}
	
	public Pipe<IL, ID, OL, OD> build() {
		return new SerialPipe<IL, ID, OL, OD>(pipes);
	}

	public <TD> SerialPipeBuilder<IL, ID, OL, TD> addDataTransform(Function<? super OD, TD> f) {
		pipes.add(Pipes.<OL, OD, TD>dataTransformingPipe(f));
		return (SerialPipeBuilder<IL, ID, OL, TD>) this;
	}

	public <TL> SerialPipeBuilder<IL, ID, TL, OD> addLabelTransform(Function<? super OL, TL> f) {
		pipes.add(Pipes.<OL, OD, TL>labelTransformingPipe(f));
		return (SerialPipeBuilder<IL, ID, TL, OD>) this;
	}
	
}
